package com.ams.thread.lesson5;

import cn.hutool.core.thread.ThreadUtil;
import lombok.extern.slf4j.Slf4j;

/**
 * @author： 乐哥聊编程(全平台同号)
 */
@Slf4j
public class Example16 {
private static MyMutexLock myMutexLock = new MyMutexLock();

    public static void main(String[] args) {
        new Thread(new Thread1()).start();
        new Thread(new Thread2()).start();
    }
    static class Thread1 implements Runnable {

        @Override
        public void run() {
            myMutexLock.lock();
            log.info("Thread1 获取到锁");
            ThreadUtil.sleep(5000);
            myMutexLock.unlock();
        }
    }
    static class Thread2 implements Runnable {

        @Override
        public void run() {
            myMutexLock.lock();
            log.info("Thread2 获取到锁");
            ThreadUtil.sleep(5000);
            myMutexLock.unlock();
        }
    }
}
